package com.kaibes.admin.token;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.module.token.service.TokenService;
import com.kaibes.web.admin.AdminMenu;
import com.kaibes.web.admin.AdminMenuRes;
import com.kaibes.web.admin.IconBox;

@Configuration
public class TokenMenuInit {
    
    private final static String KEY = "tokens";
    @Autowired
    private TokenService tokenService;
    
    @Bean
    public AdminMenu tokenMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey(KEY);
        menu.setName("令牌模块");
        menu.setIcon("fas fa-flag");
        menu.setHref("");
        menu.setSort(4);
        menu.setParentKey(AdminMenuRes.MENU_BASE);
        return menu;
    }

    @Bean
    public AdminMenu tokenManageMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("token-manage");
        menu.setName("令牌管理");
        menu.setIcon("fas fa-award");
        menu.setHref("/admin/token/manage");
        menu.setSort(1);
        menu.setParentKey(KEY);
        return menu;
    }
    
    @Bean
    public AdminMenu tokenLogMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("token-log");
        menu.setName("令牌日志");
        menu.setIcon("fas fa-file");
        menu.setHref("/admin/token/log");
        menu.setSort(2);
        menu.setParentKey(KEY);
        return menu;
    }
    
  //===============================
    @Bean
    public IconBox tokenBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(tokenService.count());
            }
        };
        iconBox.setSort(4);
        iconBox.setName("在线总数");
        iconBox.setClassAppend("bg-success");
        iconBox.setIcon("ion-happy");
        iconBox.setHref("/admin/token/manage");
        return iconBox;
    }
}
